package com.example.sourcesprng._initialization;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class SelfInitialization implements BeanPostProcessor {
    // 初始化前
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("initializationService".equalsIgnoreCase(beanName)) {
            InitializationService initializationService = (InitializationService) bean;
            initializationService.say();
        }
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    // 初始化后
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
